package com.cskaoyan.controller;

import com.cskaoyan.module.bean.BaseRespVo;
import com.cskaoyan.module.bean.UserData;
import com.cskaoyan.module.bean.param.BaseParam;
import com.cskaoyan.module.bean.vo.CollectData;
import com.cskaoyan.module.pojo.MarketUser;
import com.cskaoyan.service.AdminService;
import com.cskaoyan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin")
public class UserController {

    @Autowired
    UserService userService;

    /**
     * 查询用户，商品，货品，订单的总数
     */
    @ResponseBody
    @RequestMapping("dashboard")
    public BaseRespVo dashboard(){
        return BaseRespVo.ok(userService.dashboard());
    }

    /**
     * 查询用户信息
     * @param baseParam
     * @param username
     * @param mobile
     * @return BaseRespVo
     */
    //admin/user/list?page=1&limit=20&sort=add_time&order=desc
    @RequestMapping("user/list")
    public BaseRespVo userList(BaseParam baseParam, String username, String mobile){
        UserData userData = userService.selectUserByParam(baseParam, username, mobile);
        return BaseRespVo.ok(userData);
    }

    /**
     * 查询用户信息通过id
     * @param id
     * @return BaseRespVo
     */
    //http://182.92.235.201:8083/admin/user/detail?id=2
    @RequestMapping("user/detail")
    public BaseRespVo userDetail(Integer id){
        return BaseRespVo.ok(userService.selectUserById(id));
    }


    /**
     * 选择性修改
     * @param marketUser
     * @return
     */
    @RequestMapping("user/update")
    public BaseRespVo updateUser(@RequestBody MarketUser marketUser){
        int code = userService.updateUser(marketUser);
        if (code == 1){
            return BaseRespVo.ok(null);
        }else {
            return BaseRespVo.invalidData();
        }
    }


    /**
     * 查询address信息
     * @param param
     * @param name
     * @param userId
     * @return
     */
    @RequestMapping("address/list")
    public BaseRespVo addressList(BaseParam param,String name,Integer userId){
        return BaseRespVo.ok(userService.selectAddress(param,name,userId));
    }


    /**
     * 查询collect 信息
     * @param baseParam
     * @param userId
     * @param valueId
     * @return
     */
    @RequestMapping("collect/list")
    public BaseRespVo collectList(BaseParam baseParam,Integer userId, Integer valueId){
        CollectData collectData = userService.selectCollect(baseParam,userId,valueId);
        return BaseRespVo.ok(collectData);
    }


    /**
     * 查询会员足迹
     * @param baseParam
     * @param userId
     * @param goodsId
     * @return
     */
    @RequestMapping("footprint/list")
    public BaseRespVo footprintList(BaseParam baseParam,Integer userId, Integer goodsId){
        return BaseRespVo.ok(userService.selectFootprint(baseParam,userId,goodsId));
    }


    /**
     * 历史搜索表
     * @param baseParam
     * @param userId
     * @param keyword
     * @return
     */
    @RequestMapping("history/list")
    public BaseRespVo historyList(BaseParam baseParam,Integer userId,String keyword){
        return BaseRespVo.ok(userService.selectHistory(baseParam,userId,keyword));
    }


    /**
     * 意见反馈列表信息
     * @param baseParam
     * @param username
     * @param id
     * @return
     */
    @RequestMapping("feedback/list")
    public BaseRespVo feedbackList(BaseParam baseParam,String username,Integer id){
        return BaseRespVo.ok(userService.selectFeedbackList(baseParam,username,id));
    }
}
